package com.cn.data.jpa.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncListenableTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.web.client.AsyncRestTemplate;

import java.util.concurrent.Executor;

/**
 * Created by Administrator on 2018/11/3.
 */
@Configuration
public class WebConfig {

    @Autowired
    private AsyncListenableTaskExecutor syncHttpExecutor;

    @Bean
    public AsyncRestTemplate asyncRestTemplate() {
        return new AsyncRestTemplate(syncHttpExecutor);
    }

    @Bean("syncHttpExecutor")
    public AsyncListenableTaskExecutor taskExecutor() {
        ThreadPoolTaskScheduler executor = new ThreadPoolTaskScheduler();
        executor.setPoolSize(20);
        executor.setThreadNamePrefix("taskExecutor-");
        return executor;
    }
}
